function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}

function getLongtURL(){
	var tempID = getQueryVariable("ID")
	if(tempID){
		var tempURL = 'http://42.192.91.114:9998/?ID=' +String(tempID);
		$.getJSON(tempURL,function(result){
			console.log('getLongtURL:'+result.URL);
			window.location.href=result.URL;
		});
	}
}

function getShortURL(){
	var temp_long=document.getElementById("longurl").value;

	var tmpgetshort = 'http://42.192.91.114:9998/?URL='+String(temp_long);
    $.getJSON(tmpgetshort,function(result){
		console.log('getShortURL:'+result.URL);
		document.getElementById('shorturl').value=result.URL;

    });
}

function copy()
{
    var tmpid=document.getElementById("shorturl");
	if (tmpid.value!=""){
		tmpid.select();
		document.execCommand("Copy");
		swal("复制成功:", tmpid.value, "success");
	}else{
		swal("文本框为空！", "请输先转换长域名", "error");
	}
}
function turntourl(){
	var temp_short = document.getElementById("shorturl").value;
	if (temp_short!=""){
		window.open('https://'+temp_short);
	}else{
		swal("文本框为空！", "请输先转换长域名", "error");
	}
}
function CHeck(){
	var temp_long=document.getElementById("longurl").value;
	
			if (temp_long!=" ") {
				
				if(temp_long.includes("http://")){

				   getShortURL();
				}else if(temp_long.includes("https://")){
					
					getShortURL();
				}else{
					swal("错误的输入！", "请输入正确网址", "error");
				}
			}else{
				swal("文本框不能为空！", "请输入需要转换的长域名", "error");
			}
			
	}